from flask import Flask,request,render_template,jsonify
from dao import cpuDao as cpuDao


app = Flask(__name__,static_url_path='',static_folder='../templates/static',template_folder='../templates')

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/cpu',methods=['GET','POST'])
def cpu():
    if request.method=='GET':
        res = cpuDao.query_db("select * from cpu where id <= 6 ")
    elif request.method=='POST':
        res= cpuDao.query_db('select * from cpu where id = (%s)',args=(int(request.form['id'])+1,))

    print(res)
    return jsonify(insert_time =[x[1] for x in res],
                   cpu1=[x[2] for x in res],
                   cpu2=[x[3] for x in res],
                   cpu3=[x[4] for x in res],
                   cpu4=[x[5] for x in res] )

if __name__=="__main__":
    app.debug=True
    app.run(host='0.0.0.0',port=80)